/**
 * 
 */
package cn.maszy.service.impl.investment;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.maszy.common.DateUtils;
import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.dao.investment.B_T_Ufp_DepartmentMapper;
import cn.maszy.model.investment.B_T_Ufp_Department;
import cn.maszy.model.investment.B_T_Ufp_DepartmentExample;
import cn.maszy.model.investment.B_T_Ufp_DepartmentExample.Criteria;
import cn.maszy.service.investment.B_T_Ufp_DepartmentService;

/** 
 * @作者 Allen Shu 
 * @创建日期 2012-6-2 
 * @版本 V 1.0 
 */
@Service
public class B_T_Ufp_DepartmentServiceImpl implements B_T_Ufp_DepartmentService{
	@Autowired
	private B_T_Ufp_DepartmentMapper b_T_Ufp_DepartmentMapper;
	
	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_DepartmentService#update(cn.maszy.model.investment.B_T_Ufp_Department, cn.maszy.model.investment.B_T_Ufp_DepartmentExample)
	 */
	public int update(B_T_Ufp_Department b_T_Ufp_Department) {
		// TODO Auto-generated method stub
		 if(b_T_Ufp_Department.getUuid()==null||"".equals(b_T_Ufp_Department.getUuid())){
			 b_T_Ufp_Department.setUuid(UUID.randomUUID().toString());
			 b_T_Ufp_Department.setIsDelete(0);
			 b_T_Ufp_Department.setCreateTime(new Date());
			 b_T_Ufp_Department.setCreateUser(SessionFactory.getSessionUserRealNam());
			 return b_T_Ufp_DepartmentMapper.insert(b_T_Ufp_Department);
		 }else{
			 b_T_Ufp_Department.setUpdateTime(new Date());
			 b_T_Ufp_Department.setUpdateUser(SessionFactory.getSessionUserRealNam());
			 return b_T_Ufp_DepartmentMapper.updateByPrimaryKeySelective(b_T_Ufp_Department);
		 }
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_DepartmentService#selectOne(java.lang.String)
	 */
	public B_T_Ufp_Department selectOne(String uuid) {
		// TODO Auto-generated method stub
		B_T_Ufp_Department record=b_T_Ufp_DepartmentMapper.selectByPrimaryKey(uuid);
		return record;
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_DepartmentService#delete(java.lang.String)
	 */
	public int delete(String checkIds) {
		// TODO Auto-generated method stub
		for (String id : checkIds.split(", ")) {
			b_T_Ufp_DepartmentMapper.deleteByPrimaryKey(id);
		}
		return 1;
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_DepartmentService#count(cn.maszy.model.investment.B_T_Ufp_DepartmentExample)
	 */
	public int count(B_T_Ufp_DepartmentExample example,B_T_Ufp_DepartmentMapper b_T_Ufp_DepartmentMapper) {
		// TODO Auto-generated method stub
		return b_T_Ufp_DepartmentMapper.countByExample(example);
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_DepartmentService#selectList(cn.maszy.model.investment.B_T_Ufp_Department)
	 */
	public Pager<B_T_Ufp_Department> selectList(B_T_Ufp_Department b_T_Ufp_Department,Pager<B_T_Ufp_Department> pager) {
		// TODO Auto-generated method stub
		// 添加查询条件
		B_T_Ufp_DepartmentExample example=new B_T_Ufp_DepartmentExample();
		Criteria criteria = example.createCriteria();
		if(b_T_Ufp_Department!=null){
			if(b_T_Ufp_Department.getDepname()!=null&&!"".equals(b_T_Ufp_Department.getDepname())){
				criteria.andDepnameLike("%"+b_T_Ufp_Department.getDepname()+"%");
			}
		}else{
			criteria.andUuidIsNotNull();
		}
		example.or(criteria);
		int totalCount=new B_T_Ufp_DepartmentServiceImpl().count(example,b_T_Ufp_DepartmentMapper);
		pager.setTotalRecords(totalCount);
		example.setLimitStart(pager.getStartRecord());
		example.setLimitEnd(pager.getPageSize());
		example.setOrderByClause(pager.getOrderField()+" "+pager.getOrderDirection());
		
		// 取得总的记录条数
		List<B_T_Ufp_Department>  list=b_T_Ufp_DepartmentMapper.selectByExample(example);
		pager.setPageRecords(list);
		return pager;
	}
}
